package com.atguigu.tingshu.search.api;


import com.atguigu.tingshu.common.result.Result;
import com.atguigu.tingshu.search.service.ItemService;
import com.atguigu.tingshu.vo.search.AlbumInfoIndexVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


import java.util.List;
import java.util.Map;

@Tag(name = "专辑详情管理")
@RestController
@RequestMapping("api/search/albumInfo")
@SuppressWarnings({"unchecked", "rawtypes"})
public class ItemApiController {

	@Autowired
	private ItemService itemService;


	/**
	 * 根据专辑Id 获取详情数据
	 * @param albumId
	 * @return
	 */
	@GetMapping(value = "/{albumId}")
	@Operation(summary = "获取专辑详情")
	public Result getAlbumInfoDetail(@PathVariable(value = "albumId") Long albumId) {
		//判断前端传递的专辑Id类型是否为Long 类型，否则返回错误
		if (albumId == null) {
			return Result.fail("albumId为空");
		}
		Map<String, Object> map = itemService.getAlbumInfoDetail(albumId);
		return Result.ok(map);
	}

	@GetMapping("/preHitRank")
	@Operation(summary = "排行榜数据的提前预热")
	public Result preHitRank() {
		itemService.preHitRank();
		return Result.ok();
	}

	@GetMapping("/findRankingList/{c1Id}/{dimension}")
	@Operation(summary = "查询排行榜")
	public Result findRankingList(@PathVariable(value = "c1Id") Long c1Id,
								  @PathVariable(value = "dimension") String dimension) {

		List<AlbumInfoIndexVo> albumInfoIndexVoList = itemService.findRankingList(c1Id, dimension);
		return Result.ok(albumInfoIndexVoList);
	}
}

